﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using RetailAnalytic.Core;

namespace RetailAnalytic.Category.Engine
{
    public partial class UCPresentPerm : UserControl
    {
        public UCPresentPerm()
        {
            InitializeComponent();
        }

        public void ClearPermControl()
        {
            uce_onlyme.Checked = false;
            uce_Allcurrgroup.Checked = false;
            uce_alluser.Checked = false;
        }
        public bool InitPermControl(Int32 ClassTaskIDParent)
        {
            bool canChange = true;
            if (SetPermControl(ClassTaskIDParent) != RetailAnalyticEnum.AccessType.FULL)
            {
                canChange = false;
            }
            else
            {
                switch (SystemConfiguration.DefPermissionSetting)
                {
                    case "1":
                        uce_onlyme.Checked = true;
                        uce_Allcurrgroup.Checked = false;
                        uce_alluser.Checked = false;
                        break;
                    case "2":
                        uce_onlyme.Checked = false;
                        uce_Allcurrgroup.Checked = false;
                        uce_alluser.Checked = true;
                        break;
                    case "3":
                        uce_onlyme.Checked = false;
                        uce_Allcurrgroup.Checked = true;
                        uce_alluser.Checked = false;

                        break;
                    default:
                        {
                            Dialog.Show(Dialog_type.Error, SR.StringLibrary.GetStrMSG(SR.StringLibrary.KeyEnum.Error_NO_CONFIG_PARAM_P1,
                                Environment.StackTrace, "", new string[] { "DefPermissionSetting" }));
                            break;
                        }
                }
            }
            return canChange;
        }        
        public RetailAnalyticEnum.AccessType SetPermControl(Int32 ClassTaskID)
        {
            RetailAnalyticEnum.AccessType rez = GRetailAnalytic.Instance.security.GetPermission(ClassTaskID);
            switch (rez)
            {
                case RetailAnalyticEnum.AccessType.ONLYMASTER:
                    {
                        uce_onlyme.Checked = true;
                        uce_onlyme.Enabled = false;
                        uce_Allcurrgroup.Enabled = false;
                        uce_alluser.Enabled = false;

                        break;
                    }
                case RetailAnalyticEnum.AccessType.FULL:
                    {
                        uce_alluser.Checked = true;
                        uce_onlyme.Enabled = true;
                        uce_Allcurrgroup.Enabled = true;
                        uce_alluser.Enabled = true;
                        break;
                    }
                case RetailAnalyticEnum.AccessType.GROUP:
                    {
                        uce_Allcurrgroup.Checked = true;
                        uce_onlyme.Enabled = true;
                        uce_Allcurrgroup.Enabled = true;
                        uce_alluser.Enabled = false;

                        break;
                    }
                case RetailAnalyticEnum.AccessType.READONLY:
                    {
                        uce_onlyme.Checked = false;
                        uce_onlyme.Enabled = false;
                        uce_Allcurrgroup.Enabled = false;
                        uce_alluser.Enabled = false;

                        break;
                    }
            }
            return rez;
        }

        private void uce_onlyme_CheckedChanged(object sender, EventArgs e)
        {
            if (uce_onlyme.Checked)
            {
                uce_Allcurrgroup.Checked = false;
                uce_alluser.Checked = false;
            }
        }

        private void uce_alluser_CheckedChanged(object sender, EventArgs e)
        {
            if (uce_alluser.Checked)
            {
                uce_Allcurrgroup.Checked = false;
                uce_onlyme.Checked = false;
            }

        }

        private void uce_Allcurrgroup_CheckedChanged(object sender, EventArgs e)
        {
            if (uce_Allcurrgroup.Checked)
            {
                uce_alluser.Checked = false;
                uce_onlyme.Checked = false;
            }
        }
    }
}
